<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API 详细测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        h1, h2 {
            color: #333;
        }
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #0056b3;
        }
        pre {
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 4px;
            padding: 15px;
            overflow-x: auto;
            white-space: pre-wrap;
        }
        .error {
            color: #dc3545;
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            padding: 10px;
            border-radius: 4px;
            margin: 10px 0;
        }
        .success {
            color: #155724;
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            padding: 10px;
            border-radius: 4px;
            margin: 10px 0;
        }
    </style>
</head>
<body>
    <h1>API 详细测试</h1>
    
    <div class="container">
        <h2>测试 API 响应</h2>
        <button onclick="testAPI()">测试排行榜 API</button>
        <div id="results"></div>
    </div>

    <script>
        async function testAPI() {
            const resultsDiv = document.getElementById('results');
            resultsDiv.innerHTML = '<p>正在测试 API...</p>';
            
            try {
                // 测试排行榜 API
                const response = await fetch('https://tqi.techlinkpets3d.com/api/daka/person_rank', {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json'
                    },
                    cache: 'no-cache'
                });
                
                // 显示响应状态和头部信息
                let resultHTML = `
                    <h3>响应信息:</h3>
                    <p><strong>状态码:</strong> ${response.status}</p>
                    <p><strong>状态文本:</strong> ${response.statusText}</p>
                    <h4>响应头部:</h4>
                    <pre>${JSON.stringify([...response.headers.entries()], null, 2)}</pre>
                `;
                
                // 获取响应文本
                const responseText = await response.text();
                
                resultHTML += `
                    <h3>响应内容:</h3>
                    <p><strong>内容长度:</strong> ${responseText.length} 字符</p>
                    <p><strong>内容类型:</strong> ${typeof responseText}</p>
                    <h4>原始响应 (前 1000 字符):</h4>
                    <pre>${responseText.substring(0, 1000)}${responseText.length > 1000 ? '...' : ''}</pre>
                `;
                
                // 尝试解析 JSON
                try {
                    const jsonData = JSON.parse(responseText);
                    resultHTML += `
                        <div class="success">
                            <h3>JSON 解析成功:</h3>
                            <pre>${JSON.stringify(jsonData, null, 2)}</pre>
                        </div>
                    `;
                } catch (parseError) {
                    resultHTML += `
                        <div class="error">
                            <h3>JSON 解析失败:</h3>
                            <p><strong>错误信息:</strong> ${parseError.message}</p>
                            <p>这表明服务器返回的不是有效的 JSON 数据。</p>
                        </div>
                    `;
                }
                
                resultsDiv.innerHTML = resultHTML;
            } catch (error) {
                resultsDiv.innerHTML = `
                    <div class="error">
                        <h3>网络错误:</h3>
                        <p><strong>错误信息:</strong> ${error.message}</p>
                    </div>
                `;
            }
        }
    </script>
</body>
</html>